<?php

/*
**	Twitter OAuth Callback
**	This invisible page receives the authentication response from Twitter.
**
*/

log_message('info', 'Callback from Twitter');

if (isset($_GET['denied'])) {
    log_message('info', 'Authentication denied!');
    $this->phpsession->flashsave('message', array('class' => 'failure', 'text' => 'Authentication failed.'));
    
} elseif (isset($_GET['oauth_token'])) {
    log_message('info', 'Authentication succeeded!');
    
    $twitter = new EpiTwitter($this->config->item('twitter_consumer_key', 'ligature'), $this->config->item('twitter_consumer_secret', 'ligature'));
    
    $twitter->setToken($_GET['oauth_token']);
    $token = $twitter->getAccessToken();
    $twitter->setToken($token->oauth_token, $token->oauth_token_secret);
    
    $userInfo = $twitter->get_accountVerify_credentials();
    log_message('info', 'User ' . $userInfo->name . ' has authenticated!');
    
    $this->Ligature_User_model->login($token, $userInfo);
}

redirect('/editPost');

/* clickframes::version=1058060401::clickframes */
?>
